var express = require('express')
var fs = require('fs')
var multer = require('multer')

var request = require('./agent-request')

try {
  fs.mkdirSync('./uploads')
} catch (e) {
  if (e.code !== 'EEXIST') {
    console.error('Could not set up log directory, error was: ', e)
  }
}

var upload = multer({ dest: 'uploads/' })
var router = express.Router()
router.use('/index/upload', upload.single('file'), request.fileAgent)
router.use('/', request.common)
module.exports = router
